﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Front_DiscussionReply : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            ViewState["TID"] = Request["TID"];
        }

        DealesDataContext DDC = new DealesDataContext();
        gvTopicReplies.DataSource = DDC.GetAllReply(Convert.ToInt32(ViewState["TID"]));
        gvTopicReplies.DataBind();


        System.Data.Linq.ISingleResult<GetDiscussionByID1Result> GDBIDResult = DDC.GetDiscussionByID1(Convert.ToInt32(ViewState["TID"]), 0, 0);        
        foreach (var item in GDBIDResult)
        {            
            lblTopicName.Text = item.Topic;
        }
    }

    protected void btnPostComment_Click(object sender, EventArgs e)
    {
        DealesDataContext DDC = new DealesDataContext();
        TextBox txtPostComment = (TextBox)LoginViewToComment.FindControl("txtPostComment");
        DDC.DiscussionDetail_Insert(Convert.ToInt32(ViewState["TID"]), Membership.GetUser().ProviderUserKey.ToString(), txtPostComment.Text);
        gvTopicReplies.DataSource = DDC.GetAllReply(Convert.ToInt32(ViewState["TID"]));
        gvTopicReplies.DataBind();
        txtPostComment.Text = "";
    }

    
    protected void gvTopicReplies_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvTopicReplies.PageIndex = e.NewPageIndex;
        gvTopicReplies.DataBind();
    }
    protected void gvTopicReplies_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            System.Web.UI.HtmlControls.HtmlInputHidden hiddenUserID
                = (System.Web.UI.HtmlControls.HtmlInputHidden)e.Row.FindControl("hiddenUserID");
            Label lblUser = (Label)e.Row.FindControl("lblUserName");

            Guid userid = new Guid(hiddenUserID.Value);
            MembershipUser userObj = Membership.GetUser(userid);
            lblUser.Text = userObj.UserName + ". ";
        }

    }
}
